@use "sass:color";

.json-viewer {
  --header-title-height: 2rem;
  --hoz-gutter: 1rem;

  position: relative;
  overflow: hidden;
  max-width: 100%;
  min-width: 10rem;
  width: auto;
  flex-grow: 1;
  position: relative;
  margin-top: 0.35rem;

  .header {
    width: 100%;
    padding-left: var(--hoz-gutter);
    padding-right: var(--hoz-gutter);

    .header-group {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.5rem;

      &:first-child {
        height: var(--header-title-height);
      }
    }

    .title {
      color: $text-dark;
    }

    .menu-btn x-menuitem {
      --checkmark-margin: 0 0.3rem 0 0;
      --checkmark-height: 1.4rem;
      --checkmark-width: 1.4rem;

      &:not([togglable]) {
        padding-left: calc(var(--checkmark-width) + 0.45rem);
      }
    }

    .filter-wrap {
      position: relative;
      width: 100%;
      .clear {
        position: absolute;
        top: 50%;
        right: 0;
        border: 0;
        line-height: 0;
        color: rgba($theme-base, 0.5);
        background: transparent;
        transform: translateY(-50%);
        &:hover {
          color: $text-dark;
        }
        i {
          font-size: 1.15rem;
        }
      }
      &:hover .clear {
        visibility: visible;
      }
    }
  }

  .BksTextEditor {
    --bks-text-editor-bg-color: #{$theme-bg};
    --bks-text-editor-gutter-bg-color: #{$theme-bg};
    --bks-text-editor-propertyName-fg-color: #{color.adjust($theme-primary, $lightness: -20%)};
    --bks-text-editor-string-fg-color: #{$text-dark};
    --bks-text-editor-number-fg-color: #{$text-dark};
    --bks-text-editor-bool-fg-color: #{$text-dark};
    --bks-text-editor-null-fg-color: #{$text-dark};

    width: 100%;
    height: auto;
    padding-left: 1rem;

    &.CodeMirror, .CodeMirror-gutters {
      background-color: $theme-bg !important;
    }

    .CodeMirror-dialog.CodeMirror-dialog-top {
      margin-left: 1rem;
      padding: 0.5rem 1rem;
    }
  }


  .expandable-value {
    display: inline-flex;
    // justify-content: center;
    align-items: center;
    background: rgba($theme-base, 0.05);
    padding: 0 0.5rem;
    border-radius: 2rem;
    gap: 0.25rem;

    .material-icons {
      font-size: 1rem;
      color: $text;
    }
  }

  .community-overlay {
    position: absolute;
    z-index: 10;
    inset: 0;
    backdrop-filter: blur(6px);
    background-color: rgba($theme-bg, 0.5);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1rem;

    .title {
      display: flex;
      flex-direction: row;
      font-weight: 700;
      align-items: center;
      i.material-icons {
        margin-right: 0.5rem;
      }
    }

    .body {
      line-height: 1.25;
    }

    .actions {
      display: flex;
      flex-wrap: wrap;
      gap: 0.5rem;
      justify-content: end;
      margin-top: 1rem;
      padding-right: 0;
    }
  }

  .empty-text {
    position: absolute;
    inset: 0;
    z-index: 10;
    padding-inline: var(--hoz-gutter);
    color: $text-light;
  }

  &:not(.empty) .empty-text {
    display: none;
  }

  &.empty {
    --bks-text-editor-activeline-bg-color: transparent;
    --bks-text-editor-activeline-gutter-bg-color: transparent;
  }
}

.secondary-sidebar .json-viewer {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding-bottom: 0.5rem;

  .text-editor-wrapper {
    flex: 1 1 auto;
    height: 100%;
    position:relative;

    .BksTextEditor {
      position: absolute;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      height: 100%
    }
  }
}

.truncatable-value .more {
  @include btn;
  @include btn-flat;
  margin-left: 0.5rem;
  min-width: fit-content;
  font-size: 0.85rem;
  font-weight: normal;
  cursor: pointer;
  height: 1.3rem;
  padding: 0 0.5rem;
  margin-left: 0.25rem;
  text-decoration: none;
  user-select: none;
  border-radius: 0.25rem;
}
